

import persistent from '../common/persistentUtil'

export default {

    install (Vue) {

        Vue.directive("hasPermission",{
            bind:function (el,binding,vnode) {

                let btnPermission = binding.value;
                let permissions = persistent.getPermissions();
                let flag = false;

                if(permissions && Array.isArray(permissions)){

                    if(permissions.indexOf(btnPermission) > -1){
                        flag = true;
                    }
                }
                if( ! flag){
                    //让父节点删除自己
                    if (!el.parentNode) {
                        el.style.display = 'none'
                    } else {
                        el.parentNode.removeChild(el)
                    }
                    console.log("按钮无权限:" + btnPermission);
                }
            }
        })
    }



}